<?php
/* 
 * Amnesia is Copyright (c) 2010 Mark Russell
 * 
 * Contact: info@amnesia-app.com	
 * 
 * This file is part of Amnesia.
 * 
 * Amnesia is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Amnesia is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Amnesia. If not, see <http://www.gnu.org/licenses/>.
 *
 */

session_start();
include("../db/db.php");
include("../login/login.php");

// Send unlogged-in access attempts straight to the login form
if(!$logged_in)
	header("Location: ../");

// Get the current user from the session

$query = "SELECT `user_id`, `firstname`, `lastname`, `timeout`, `count` FROM `user` WHERE `username`='" . $user_name . "'";

if(!($result = @ mysql_query ($query, $con)))
	showerror();

while($array = mysql_fetch_array($result)) {
	$id = $array['user_id'];
	$firstname = $array['firstname'];
	$lastname = $array['lastname'];
	$timeout = $array['timeout'];
	$user_count = $array['count'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Amnesia. Feel free to forget.</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" href="../css/amnesia.css" type="text/css" media="screen" />
	<script type="text/javascript" src="../lib/jquery.js"></script>
	<script type="text/javascript" src="../lib/passpack.js"></script>
	<script type="text/javascript" src="../lib/timers.js"></script>
	<script type="text/javascript" src="../lib/tinysort.js"></script>
	<script type="text/javascript" src="../lib/zero_clipboard.js"></script>
	<script type="text/javascript" src="../lib/password.js"></script>
	<script type="text/javascript" src="../lib/truncate.js"></script>
	<script type="text/javascript" src="core/application.js"></script>
<?
	// Set Javascript global vars from db call
	echo "<script type=\"text/javascript\" language=\"javascript\">";
	echo "var user = \"" . $id . "\";";
	echo "var lock_out_time = \"" . $timeout . "s\";";
	echo "var user_count = " . $user_count . ";";
	echo "</script>";
?>
</head>
<body>
	<div id="main">
		<div id="container">
			<div id="left_retainer"></div>
			<div id="col1">
				<img src="../img/core/amnesia_logo.jpg" alt="Amnesia. Feel free to forget" width="187" height="184"/>
				<div id="login_status_locked">
					<strong>Amnesia is locked</strong><br/>Please enter your keyphrase
				</div>
				<div style="display: none;" id="login_status_unlocked">
					<strong>Amnesia is unlocked</strong><br/><a id="lock" href="javascript:void(0)" title="Lock Amnesia"><img id="login_lock_button" src="../img/buttons/lock_amnesia_link.png" alt="lock_amnesia_link" width="103" height="22"/></a>
				</div>
				<div id="user_status">
					<strong>Signed-in as <? echo $firstname . "&nbsp;" . $lastname ?></strong><br/>
					<img src="../img/core/arrow_small.png" alt="arrow_small" width="4" height="7"/> <a class="col1" href="../login/logout.php">Sign-out</a><br/>
					<img src="../img/core/arrow_small.png" alt="arrow_small" width="4" height="7"/> <a class="col1" href="../prefs">Preferences</a>
				</div>
			</div>
			
			<!-- Locked single column -->
			<div id="col_container_locked">
				<div id="status_locked">
					<div id="status_left"></div>
					<div id="status_right">
						<div id="amnesia_locked">Amnesia is locked<img class="status_icn" src="../img/core/lock_icon.png" alt="lock_icon" width="9" height="12"/></div>
						<div class="loading" style="display: none;"><span>Loading </span><img class="status_icn" src="../img/core/loading.gif" alt="loading" width="14" height="14"/></div>
					</div>
				</div>
				<div id="master_key" style="display: none;">
					<div id="master_key_contents">
						<p id="key_message">Please enter your master keyphrase:</p>
						<p style="display: none;" id="key_error" class="error">Sorry, that master keyphrase is invalid, please try again:</p>
						<form action="#">
							<fieldset>
								<input type="password" name="master_key" id="master_key_input" /> 
								<a id="unlock" href="javascript:void(0)"><img id="key_button" src="../img/buttons/unlock_amnesia_link.png" alt="unlock_amnesia_link" width="116" height="22"/></a>
							</fieldset>
						</form>
					</div>
				</div>
				
			</div>
			
			<!-- Secure three columns -->
			<div style="display: none;" id="col_container_secure">
				<div id="status_secure">
					<div id="status_left">
<? 
// Add different message dependent on $user_count
if ($user_count == 0)
	echo "<span id=\"user_count\">Amnesia remembers things so you can forget them. Start by adding some items.</span>";
else if ($user_count == 1)
	echo "<span id=\"user_count\">Amnesia has remembered " . $user_count . " thing so you don't have to.</span>";
else
	echo "<span id=\"user_count\">Amnesia has remembered " . $user_count . " things so you don't have to.</span>";
?>
					</div>
					<div id="status_right">
						<div class="loading" style="display: none;"><span>Loading </span><img class="status_icn" src="../img/core/loading.gif" alt="loading" width="14" height="14"/></div>
						<p id="write_success" class="message" style="display: none;">Item successfully updated.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
						<p id="new_success" class="message" style="display: none;">New item successfully added.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
						<p id="delete_success" class="message" style="display: none;">Item successfully deleted.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
						<p id="item_blank" class="message" style="display: none;">Can't save this item without a title.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
						<p id="username_copied" class="message" style="display: none;">Username copied to clipboard.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
						<p id="password_copied" class="message" style="display: none;">Password copied to clipboard.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
						<p id="serial_copied" class="message" style="display: none;">Serial number copied to clipboard.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
						<p id="cardno_copied" class="message" style="display: none;">Card number copied to clipboard.<img class="status_icn" src="../img/core/status_star.png" alt="status_star" width="12" height="12"/></p>
					</div>
				</div>
				<div id="col2">
					<div id="col2_title">
						Category
					</div>
					<div class="scroll_holder">
						<ul id="cat_list"></ul>
					</div>
				</div>
				<div id="col3">
					<div id="col3_title">
						<div id="col3_title_text">Item</div>
						<div id="col3_title_button"><a id="create_new" href="javascript:void(0)" title="Add a new item"><img src="../img/buttons/add_item_title_link.png" alt="add_item_title_link" width="75" height="22"/></a></div>
					</div>
					<div class="scroll_holder">
						<ul id="item_list"></ul>
					</div>
				</div>
				<div id="col4">
					<!-- Col4 Titles -->
					<div id="col4_title_empty">
						<div class="col4_title_text">Detail</div>
						<div class="col4_title_button"></div>
					</div>
					<div style="display: none;" id="col4_title_read">
						<div class="col4_title_text">Detail</div>
						<div class="col4_title_button"><a class="edit" href="javascript:void(0)" title="Edit item"><img src="../img/buttons/edit_item_title_link.png" alt="edit_item_title_link" width="75" height="22"/></a> <a class="delete" href="javascript:void(0)" title="Delete item"><img src="../img/buttons/delete_item_title_link.png" alt="delete_item_title_link" width="88" height="22"/></a></div>
					</div>
					<div style="display: none;" id="col4_title_edit">
						<div class="col4_title_text">Detail</div>
						<div class="col4_title_button"><a class="close" href="javascript:void(0)" title="Cancel without saving"><img src="../img/buttons/cancel_edit_link.png" alt="cancel_edit_link" width="87" height="22"/></a> <a class="delete" href="javascript:void(0)" title="Delete item"><img src="../img/buttons/delete_item_title_link.png" alt="delete_item_title_link" width="88" height="22"/></a></div>
					</div>
					<div style="display: none;" id="col4_title_add">
						<div class="col4_title_text">Detail</div>
						<div class="col4_title_button"><a class="close_create_new" href="javascript:void(0)" title="Cancel without saving"><img src="../img/buttons/cancel_add_title_link.png" alt="cancel_add_title_link" width="87" height="22"/></a></div>
					</div>
					<div id="col4_container">
						
						<?php include 'includes/detail_empty.php'; ?>
						<?php include 'includes/detail_web.inc.php'; ?>
						<?php include 'includes/detail_hosted.inc.php'; ?>
						<?php include 'includes/detail_phone.inc.php'; ?>
						<?php include 'includes/detail_license.inc.php'; ?>
						<?php include 'includes/detail_cards.inc.php'; ?>
						<?php include 'includes/detail_banking.inc.php'; ?>
						<?php include 'includes/detail_email.inc.php'; ?>
						<?php include 'includes/detail_computer_user.inc.php'; ?>
						<?php include 'includes/detail_hardware.inc.php'; ?>
						<?php include 'includes/detail_certificates.inc.php'; ?>
						<?php include 'includes/detail_notes.inc.php'; ?>
						
					</div>
				</div>
			</div>
			<!-- Delete modal panel -->			
			<div style="display: none;" class="lightbox_bg"></div>
			<div style="display: none;" id="delete_confirm" class="modal">
				<div id="delete_message">Are you sure you want to delete this item?</div>
				<div id="delete_buttons"><a id="cancel_delete" href="javascript:void(0)"><img src="../img/buttons/cancel_link.png" alt="cancel_link" width="50" height="22"/></a> <a class="confirm_delete" href="javascript:void(0)"><img src="../img/buttons/delete_item_panel_link.png" alt="delete_item_panel_link" width="76" height="22"/></a></div>
			</div>
		</div>
	</div>
</body>
</html>
